package com.panda.mybatisplus.demo.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.panda.mybatisplus.demo.dao.UserMapper;
import com.panda.mybatisplus.demo.domain.po.User;
import com.panda.mybatisplus.demo.domain.vo.UserVO;
import com.panda.mybatisplus.demo.service.UserService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {
    @Resource
    private UserMapper userMapper;

    @Override
    public UserVO getUserById(Long id) {
        User user = getBaseMapper().selectById(id);
        UserVO userVO = new UserVO();
        BeanUtils.copyProperties(user, userVO);
        return userVO;
    }

    @Override
    public Integer updateById(UserVO userVO) {
        User user = new User();
        BeanUtils.copyProperties(userVO, user);
        return getBaseMapper().updateById(user);
    }
}
